package com.jic.market.controller.manage;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.market.api.manage.PromotionMutexApi;
import com.jic.market.request.PromotionMutexRequest;
import com.jic.market.response.PromotionMutexDetailResponse;
import com.jic.market.service.PromotionMutexService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: MJ
 * @date: 2020-05-11
 * @remark: 活动互斥服务
 */
@RestController
@RequestMapping("/promotionMutex")
@Api(tags = {"活动互斥服务"})
@Slf4j
public class PromotionMutexController implements PromotionMutexApi {

    private final static Logger logger = LoggerFactory.getLogger(PromotionMutexController.class);

    @Resource
    private PromotionMutexService promotionMutexService;


    /**
     * 根据互斥商品查询对应互斥活动
     * @param request
     * @return
     */
    @PostMapping("/getPromotionMutexListByProductId")
    @ResponseBody
    @ApiOperation(value = "根据互斥商品查询对应互斥活动")
    @Override
    public RestResult<PageResult<PromotionMutexDetailResponse>> getPromotionMutexListByProductId(@RequestBody PromotionMutexRequest request) {
        try {
            log.debug("getPromotionMutexListByProductId " + request);
            PageResult<PromotionMutexDetailResponse> pageResult = promotionMutexService.getPromotionMutexListByProductId(request);
            return RestResult.success(pageResult);
        }catch (Exception e){
            log.error("Market getPromotionMutexListByProductId error：",e);
            return RestResult.error("9999","系统异常，查询互斥活动失败");
        }
    }
}
